package com.itheima.controller;

import com.itheima.domain.Student;
import com.itheima.service.impl.StudentServiceImpl;
import com.itheima.utils.AgeUtils;

import java.util.Scanner;

public class StudentControler extends BaseController implements BaseStudentController {
    /*StudentServiceImpl studentService = new StudentServiceImpl();
    Scanner sc = new Scanner(System.in);
    //@Override
    public void addStudent() {


        System.out.println("请输入学生id:");
        String id;
        while (true){
            id = sc.nextLine();
            //调用isExists()方法查看是否已经存在
            if (!studentService.isExists(id)){
                break;
            }else
                System.out.println("该id已存在,请重新输入");
        }
        Student student = inputStudent(id);
        studentService.addStudent(student);
    }

    public Student inputStudent(String id) {
        System.out.println("请输入学生姓名:");
        String name = sc.nextLine();
        System.out.println("请输入学生生日(格式为xxxx-xx-xx):");
        String birthday;
        String age;
        while (true){
            try {
                birthday = sc.nextLine();
                age = AgeUtils.getAge(birthday);
                break;
            } catch (Exception e) {
                System.out.println("输入的生日格式错误;正确格式示例:1900-1-1");
                continue;
            }
        }
        return new Student(id,name,age,birthday);
    }

    //@Override
    public void delectStudent() {
        if (studentService.findAllStudent() == null){
            System.out.println("当前系统无数据,请先添加");
            return;
        }
        System.out.println("请输入想要删除的学生id");
        String id ;
        while (true){
            id = sc.nextLine();
            //调用isExists()方法查看是否已经存在
            if (studentService.isExists(id)){
                break;
            }else
                System.out.println("该id不存在,请重新输入");
        }
        studentService.delectStudent(id);
        System.out.println("删除成功");

    }

    //@Override
    public void updateStudnet() {
        System.out.println("请输入想要修改的学生id");
        String id ;
        while (true){
            id = sc.nextLine();
            //调用isExists()方法查看是否已经存在
            if (studentService.isExists(id)){
                break;
            }else
                System.out.println("该学生不存在,请重新输入");
        }
        Student student = inputStudent(id);
        studentService.updataStudent(student);
    }

    //@Override
    public void findAllStudent() {
        Student[] students = studentService.findAllStudent();
        if (students == null)
            System.out.println("当前系统无数数据,请添加后查看");
        else {
            System.out.println("学号\t\t姓名\t年龄\t\t生日");
            for (int i = 0; i < students.length; i++) {
                Student stu = students[i];
                System.out.println(stu.getId() + "\t" + stu.getName() + "\t" + stu.getAge() + "\t\t" + stu.getBirthday());
            }
        }
    }*/
}
